package com.mywebbox.mycraftplugin;

import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
import java.util.logging.Level;
import java.util.logging.Logger;
//test
public class I18n {

	private static final String I18nFileName = "languages";
	private static final Locale defaultLocale = Locale.getDefault();

	private static String msg(String str, Locale locale) {
		try {
			ResourceBundle bundle = ResourceBundle.getBundle(I18nFileName,
					locale);
			return bundle.getString(str);
		} catch (MissingResourceException ex) {
			Logger.getLogger("minecraft").log(Level.WARNING,
					"Can not load the translate file");
		}
		return "translate name : " + str;
	}

	private static String msgFormat(String str, Locale locale, Object[] objects) {
		String msg = msg(str, locale);
		MessageFormat msgFormat = new MessageFormat(msg);
		return msgFormat.format(objects);
	}

	public static String _(String str) {
		return msg(str, defaultLocale);
	}

	public static String _(String str, Locale locale) {
		return msg(str, locale);
	}

	public static String _(String str, Object[] objects) {
		return msgFormat(str, defaultLocale, objects);
	}

	public static String _(String str, Locale locale, Object[] objects) {
		return msgFormat(str, locale, objects);
	}

}
